<?php
/*
 * Copyright (C) 2014 OpenSIPS Project
 *
 * This file is part of opensips-cp, a free Web Control Panel Application for 
 * OpenSIPS SIP server.
 *
 * opensips-cp is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * opensips-cp is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

###############################################################################
# Attention : advanced options !!

 //this is a very important parameter
 $module_id = "channel";
 $custom_config[$module_id] = array ();

 // a custom global name for the tool
 $custom_config[$module_id]['custom_name'] = "SMS Gateway";
 

//if you want submenu (horizontal) items add them here:

 $custom_config[$module_id]['submenu_items'] = array(
 					"0"	=> "短信通道"
				);




/* config for each submenu item */

/*
table: globalblacklist
+---------------+------------------+------+-----+---------+----------------+
| Field         | Type             | Null | Key | Default | Extra          |
+---------------+------------------+------+-----+---------+----------------+
| id            | int(10) unsigned | NO   | PRI | NULL    | auto_increment | 
| prefix        | char(64)         | NO   |     |         |                | 
| whitelist     | tinyint(1)       | NO   |     | 0       |                | 
| description   | char(255)        | YES  |     |         |                | 
+---------------+------------------+------+-----+---------+----------------+

####################################################################################
#																				   #
# Uncomment bellow this line - follow the example and adapt it to your DB table    #
#																				   #
####################################################################################
*/

function net_status_display($key, $text, $link) {
        if($text == "不可用")
        return "<span style='color:red;'>不可用</span>";
        return "<span style='color:green;'>可用</span>";
}

function enabled_display($key, $text, $link) {
        if($text == "禁用")
        return "<span style='color:red;'>已禁用</span>";
        return "<span style='color:green;'>已启用</span>";
}

$custom_config[$module_id][0]['custom_table'] = "sms_channel";
$custom_config[$module_id][0]['custom_table_primary_key'] = "id";
$custom_config[$module_id][0]['custom_table_order_by'] = "id";
$custom_config[$module_id][0]['per_page'] = 25;
$custom_config[$module_id][0]['page_range'] = 3;

/*
 Columns definition:
	- header - the header title used to label this column (mandatory)
	- type - how to display/handle the data - text / combo / textarea (mandatory)
	- key - the key restrictions for this column (they will be checked prior to DB op) - PRI/UNI (optional)
	- tip - tip/explanation to be attached to this column in the add/edit forms (optional)
	- validation_regex - a regular expression to check the inserted value; only for text type (optional)
	- is_optional - if a value must be provided or not for the column (mandatory)

	- show_in_add_form - if to be shown in the add form (optional)
	- show_in_edit_form - if to be shown in the edit form (optional)
	- searchable - if to be listed as field in the search form (optional)
	- disabled - if the disabled attribute should be set to this column (optional)
	- readonly - if the readonly attribute should be set to this column (optional)
	- visible - if the column should be displayed in the table (optional)
	- value_wrapper_func - php function like func($key, $text, $link) to return 
		a custom string to be displayed instead of the real value; parameters are:
		- $key - the name of the column
		- $text - the value of the column
		- $link - an assoc array with all the values of the DB row( i.e $text = $link[$key] )
		This function can be use to build links or images around the values to be displayed (optional).

	- default_value - optional default value to pre-populate the column in the add form
	- default_display - a default display text corresponding to the default value if the type is COMBO
	- combo_default_values - assoc array (value -> display) for definiting static COMBOs
		Example: array("1"=>"Yes","0"=>"No")
	- combo_table, combo_value_col, combo_display_col, combo_hook_col - set of attributes for
		defininig dynamic combos, with data from DB; table and value are mandatory in this
		configuration; display may be optionaly used; similar the hook - this has no impact
		over the display of the combo; it simply creates a "hook" attribute inside the
		"option" html tag, which may be used by JS function to enable/disable/remove 
		the value during runtime.
	
	- events - a string that optionaly may define JS events for the input/select field
		Example: "onChange=\"runJSfunction();\" "
 
	- textarea_display_size - optional value used when a textarea_label_column is not specified, and
		 indicates how many characters should be shown from the text area content. Default is 50.
*/

 
 $custom_config[$module_id][0]['custom_table_column_defs'] = array (	
			"id" 		=> 	array (
					"header" 		=> "ID",
					"type"			=> "text",
					"key"			=> "PRI",
					"show_in_add_form" 	=> false,
					"show_in_edit_form"	=> false,
					"searchable" 		=> false,
					"visible"		=> false
			), 
			"channel_no"	=> 	array (
					"header" 		=> "通道号",
					"type"			=> "text",
					"key"			=> NULL,
					"tip"			=>"通道号，字母数字组合，长度不超过30, 须保证唯一性，一旦设置不能更改",
					"validation_regex" 	=> "^[A-Za-z0-9]+$",
					"show_in_add_form" 	=> true,
					"show_in_edit_form"	=> false,
					"searchable" 		=> true
			), 
			"channel_name" 	=> 	array (
					"header" 		=> "通道名称",
					"type"			=> "text",
					"key"			=> NULL,
					"tip"			=> "通道名称",
					"show_in_add_form" 	=> true,
					"show_in_edit_form"	=> true,
					"searchable" 		=> true,
					"searchPattern"         => "like"
			),
			"operator_type"  =>	array (       
					"header" 		=> "运营商类型",
					"type"  		=> "combo",
					"key"			=> NULL,
					"show_in_add_form" 	=> true,
					"show_in_edit_form"	=> true,
					"searchable" 		=> false,
                                        "combo_default_values"  => array("0"=>"移动", "1"=>"联通", "2"=>"电信", "5"=>"广电", "3"=>"全网", "4"=>"国际", "6"=>"移动/联通", "7"=>"移动/电信", "8"=>"移动/广电", "9"=>"联通/电信", "10"=> "联通/广电", "11"=>"电信/广电", "12"=>"移动/联通/电信", "13"=>"移动/联通/广电", "14"=>"联通/电信/广电"),
                                        "default_value"         => "0"
			),
                        "protocol"  =>     array (
                                        "header"                => "协议类型",
                                        "type"                  => "combo",
                                        "key"                   => NULL,
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                                        "combo_default_values"  => array("0"=>"移动CMPP 2.0", "1"=>"移动CMPP 3.0", "2"=>"SGIP联通", "3"=>"电信SMGP", "4"=>"国际SMPP"),
                                        "default_value"         => "0"
                        ),
                        "channel_type"  =>     array (
                                        "header"                => "通道类型",
                                        "type"                  => "combo",
                                        "key"                   => NULL,
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                                        "combo_default_values"  => array("0"=>"国内通道", "1"=>"国际通道"),
                                        "default_value"         => "0"
                        ),
                        "channel_ip"  =>      array (
                                        "header"                => "通道IP",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "通道IP",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "port"  =>      array (
                                        "header"                => "端口号",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "端口号",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "login_name"  =>      array (
                                        "header"                => "登录用户名",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "登录用户名",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "password"  =>      array (
                                        "header"                => "登录密码",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "登录密码",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
			"src_id"  =>      array (
                                        "header"                => "接入码",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "接入码，一般106***",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "msg_src"  =>      array (
                                        "header"                => "企业代码",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "企业代码，对应submit的msg_src",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "speed"  =>      array (
                                        "header"                => "单连接速度",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "单连接速度",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "max_connect"  =>      array (
                                        "header"                => "最大连接数",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "最大连接数",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
                        "price"  =>      array (
                                        "header"                => "成本价(元)",
                                        "type"                  => "text",
                                        "key"                   => NULL,
                                        "tip"                   => "成本价(元)",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
					"default_value"         => "0"
                        ),
                        "remove_sign_on_send"  =>      array (
                                        "header"                => "是否移除签名",
                                        "type"                  => "combo",
                                        "key"                   => NULL,
                                        "tip"                   => "是否在短信发送时移除签名",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                                        "combo_default_values"  => array("0"=>"否", "1"=>"是"),
                                        "default_value"         => "0"
                        ),
                        "filter_operator_type"  =>      array (
                                        "header"                        => "是否按运营商过滤号码",
                                        "type"                          => "combo",
                                        "key"                           => NULL,
                                        "tip"                           => "是否过滤其它运营商号码",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                                        "combo_default_values"  => array("0"=>"否", "1"=>"是"),
                                        "default_value"         => "0"
                        ),
                        "sign_whitelist"  =>      array (
                                        "header"                        => "短信签名限制",
                                        "type"                          => "textarea",
                                        "textarea_display_size"         => "32",
                                        "key"                           => NULL,
                                        "tip"                           => "允许发送的短信签名列表，英文逗号分隔",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                                        "default_value"         => "无限制"
                        ),
                        "net_status"  =>      array (
                                        "header"                => "可用状态",
                                        "type"                  => "combo",
                                        "key"                   => NULL,
                                        "tip"                   => "是否可用",
                                        "show_in_add_form"      => false,
                                        "show_in_edit_form"     => false,
                                        "searchable"            => false,
                                        "combo_default_values"  => array("0"=>"不可用", "1"=>"可用"),
                                        "default_value"         => "0",
					"value_wrapper_func"    => 'net_status_display'
                        ),
                        "enabled"  =>     array (
                                        "header"                => "是否启用",
                                        "type"                  => "combo",
                                        "key"                   => NULL,
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                                        "combo_default_values"  => array("0"=>"禁用", "1"=>"启用"),
                                        "default_value"         => "1",
					"value_wrapper_func"    => 'enabled_display'
                        ),
                        "remark"  =>      array (
                                        "header"                => "备注",
                                        "type"                  => "textarea",
                                        "textarea_display_size" => "32",
                                        "key"                   => NULL,
                                        "tip"                   => "备注",
                                        "show_in_add_form"      => true,
                                        "show_in_edit_form"     => true,
                                        "searchable"            => false,
                        ),
	);



 //need to reload 0 or 1
 $custom_config[$module_id][0]['reload'] = 0;

 //if you need reload please specify the MI command to be ran
 $custom_config[$module_id][0]['custom_mi_command'] = "reload_blacklist";
 
 //the system ID to send the reload MI command to
 $talk_to_this_assoc_id = 1;


##############################################
######### CUSTOM SEARCH OPTIONS ##############
##############################################
$custom_config[$module_id][0]['custom_search'] = array(
	"enabled" => true,
	"action_script" => "custom_actions/search.php"
);

##############################################
####### CUSTOM ACTIONS COLUMNS ###############
##############################################
$custom_config[$module_id][0]['custom_action_columns'] = array (
	"0" => array(
			"header" => "删除",
			"show_header" => false,
			"type" => "link",
			"action" => "delete",
			"icon" => "../../../images/share/delete.png",
			"action_script" => "custom_actions/delete.php",
			"action_template" => "template/custom_templates/delete.php",
			"events" => "onclick=\"return confirmDelete()\""
	),
	"1" => array(
                        "header" => "编辑",
                        "show_header" => false,
                        "type"	=> "link",
                        "action" => "edit",
                        "icon" => "../../../images/share/edit.png",
                        "action_script" => "custom_actions/edit.php",
                        "action_template" => "template/custom_templates/edit.php"
        )
);
##############################################
####### CUSTOM ACTIONS BUTTON  ###############
##############################################

$custom_config[$module_id][0]['custom_action_buttons'] = array (
	"0" => array(
		"text" => "Add",
		"action" => "add",
		"style" => "formButton",
		"action_script"	=> "custom_actions/add.php",
		"action_template" => "template/custom_templates/add.php"
	)
);

?>

